<?php
//include_once("db.php");
include_once("Pc.php");

class PcManager implements Iterator {
	public $list;

	function __construct() {
		db_init();

		$this->list = array();
	}

	/***************************************************/
	/* The following are for interation. (aka foreach) */
	/***************************************************/

    public function rewind() {
		$query = "SELECT * FROM n_wb_pc"
				." WHERE isHidden=0 AND style='pc'"
				." ORDER BY dt_access DESC";
		$result = mysql_query($query);
		while($next = mysql_fetch_assoc($result)) {
			// create new pc object
			$pc = new Pc($next["id"]);

			// set some data
			$pc->style = $next["style"];
			$pc->name = $next["name"];
			$pc->isHidden = $next["isHidden"];
			$pc->dt_access = $next["dt_access"];

			// append to list
			$this->list[$next["id"]] = $pc;
		}
    }
  
    public function current() {
        return current($this->list);
    }
  
    public function key() {
        return key($this->list);
    }
  
    public function next() {
        return next($this->list);
    }
  
    public function valid() {
        return (current($this->list) != null);
    }
}

?>
